package cc.rboot.permission.configuration;

import cc.rboot.permission.core.DefaultResourcePermission;
import cc.rboot.permission.core.ForbidResourcePermission;
import cc.rboot.permission.holder.ResourcePermissionHolder;
import cc.rboot.permission.interceptor.ResourcePermissionInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@Import({ResourcePermissionHolder.class, ResourcePermissionInterceptor.class, DefaultResourcePermission.class, ForbidResourcePermission.class})
public class RBootPermissionConfiguration implements WebMvcConfigurer {

    @Resource
    public ResourcePermissionInterceptor resourcePermissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(resourcePermissionInterceptor)
                .addPathPatterns("/**");
    }
}
